<?php 
	/**
	 * 每天删除30天以前的数据
	 */

	include_once dirname(dirname(__FILE__))."/include/common.inc.php";
	include_once dirname(dirname(__FILE__))."/youyuan/function.youyuan.php";

	
	function getUser($id=0,$ymd)
	{
		global $conn;
		$tblName = getTblName($ymd);
		$sql = "select * from $tblName where fetch_date='$ymd' and `from`='youyuan' order by rand() limit 1000";
		$user = $conn->query($sql);
		$randuser = array();
		while ($row = $conn->fetch_array($user)) {
			if ($row['gender'] == 1) {
				$row['gender'] = '男';
			}else{
				$row['gender'] = '女';
			}
			if ($row['has_photo'] == 1) {
				$row['has_photo'] = '有照片';
			}else{
				$row['has_photo'] = '无照片';
			}
			$randuser[] = $row;
		}
		return $randuser;
	}
//抓取日期，默认为昨天
	$ymd =  date("Y-m-d", time()-60*60*24);
	$user = getUser();
	$file = 'user.txt';
$filename = '75464312.html';
	$page = file_get_contents($filename);
	$page = str_replace(array(" ","\t","\n","\r","&nbsp;"), "", $page);
file_put_contents('a.html', $page);
exit;

foreach ($user as $key => $value) {
	$page_dir = ROOT_PATH."/youyuan/pages";
	$page_dir = $page_dir."/".$ymd."/";
	$filename = $page_dir.$value['source_user_id'].'.html';
	$page = file_get_contents($filename);
	$page = str_replace(array(" ","\t","\n","\r","&nbsp;"), "", $page);
	preg_match('%<divclass="floatLfontP"title="男士"style="font-size:22px;">(.*?)</div>%i', $subject)
	$line = implode("\t", $value);
	file_put_contents($file,$line."\n", FILE_APPEND);
}
$value = 'youyuan';
$subject = '竞争对手'.$value.'数据提取';
$content = '竞争对手'.$value.'数据提取见附件';
$att = array($file);
sendMailEx($subject, $content,$att);

?>